package cn.yourkingda.service.impl;

import java.util.List;

import org.nutz.dao.Cnd;
import org.nutz.service.NameEntityService;

import cn.yourkingda.pojo.Employee;
import cn.yourkingda.pojo.Food;
import cn.yourkingda.service.EmployeeService;
import cn.yourkingda.util.MyJson;

public class EmployeeServiceImpl extends NameEntityService<Employee> implements EmployeeService{

	
	/**
	 * 更新员工
	 */
	public MyJson updateEmployee(Employee employee) {
		String[] msgs={"更新成功","新增成功","编号已存在"};
		int status=0,msgNo=0;
			if(employee.getId()>0){
				this.dao().updateWith(employee, "employeetype");
				status=1;
				msgNo=0;
			}else{
				List list = this.dao().query(Employee.class, Cnd.where("employeeno","=",employee.getEmployeeno()));
				if(list.size()>0){
					status=-1;
					msgNo=2;
				}
				if(status!=-1){
				this.dao().insertWith(employee, "employeetype");
				status=1;
				msgNo=1;}
			}
		
		MyJson myJson = new MyJson();
		myJson.setStatus(status);
		myJson.setMsg(msgs[msgNo]);
		return myJson;
		
	}

	

	public void delEmployee(int id) {
		// TODO Auto-generated method stub
		this.dao().delete(Employee.class,id);
	}

	
	public Employee getEmployee(Employee employee) {
		// TODO Auto-generated method stub
		
		return this.dao().fetch(Employee.class,employee.getId());
	}

	/**
	 * 展现数据
	 */
	public List listEmployee() {
		// TODO Auto-generated method stub
		List<Employee> employeeList = this.dao().query(Employee.class,Cnd.where("id",">",0).desc("id"));
		return employeeList;
	}

}
